package com.glance.browser.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.KnowledgeItem;

@Transactional(readOnly = true)
public interface KnowledgeItemRepository extends JpaRepository<KnowledgeItem, Long>  {

	@Modifying
	@Query("delete from KnowledgeItem where id > :id")
	void deleteAllAfter(@Param("id") long id);
	
	List<KnowledgeItem> findByTitle(String title);

	@Query("from KnowledgeItem k inner join k.author a where a.firstName = :firstName and a.lastName = :lastName")
	List<KnowledgeItem> findByAuthor(@Param("firstName") String firstName,@Param("lastName") String lastName);

}
